package com.ica.model.command;

import java.util.List;
import java.util.Vector;

import android.content.Context;
import java.util.Collection;

/**
 * @author   Hector
 */
public class ComposedCommand extends AbstractCommand {
	
	/**
	 */
	private Vector<AbstractCommand> commands;
	/**
	 */
	private String name = null;

	public ComposedCommand(String name) {	
		super();
		this.name = name;
		commands = new Vector<AbstractCommand>();
	}
	
	/**
	 * @return
	 * @uml.property  name="name"
	 */
	@Override
	public String getName() {
		return name;
	}
	
	/**
	 * @param  name
	 * @uml.property  name="name"
	 */
	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public boolean execute(Context context) {	
		boolean res = true;
		for(AbstractCommand command : commands) {
			boolean temp = command.execute(context);
			res = res && temp;
		}
		log("Composed Command executed");
		return res;
	}
	
	@Override
	public void addCommand(AbstractCommand command) throws UnsupportedOperationException {	
		commands.add(command);
	}

	@Override
	public void removeCommand(AbstractCommand command) throws UnsupportedOperationException {	
		commands.remove(command);
	}
	
	/**
	 * @return
	 * @uml.property  name="commands"
	 */
	@Override
	public List<AbstractCommand> getCommands() {
		return commands;
	}
	
	@Override
	public String toString() {
		return name;
	}

	/**
	 * @uml.property  name="command"
	 * @uml.associationEnd  multiplicity="(0 -1)" aggregation="composite" inverse="composedCommand:com.ica.model.command.AbstractCommand"
	 */
	private Collection<AbstractCommand> command;

	/**
	 * Getter of the property <tt>command</tt>
	 * @return  Returns the command.
	 * @uml.property  name="command"
	 */
	public Collection<AbstractCommand> getCommand() {
		return command;
	}

	/**
	 * Setter of the property <tt>command</tt>
	 * @param command  The command to set.
	 * @uml.property  name="command"
	 */
	public void setCommand(Collection<AbstractCommand> command) {
		this.command = command;
	}
}
